<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        input {
            width: 600px;
            height: 40px;
            display: block;
            margin: 100px auto 0;
            font-size: 20px;
        }

        .box {
            text-align: center;
            width: 100px;
            height: 100px;
            background-color: #ccc;
            line-height: 100px;
            margin: 20px auto 0;
        }
    </style>
</head>

<body>
    <h3>使用防抖函数</h3>
    <input type="text">

    <script src="./fangdou.js"></script>
    <script>
        // 监听输入框的值变化
        var inp = document.querySelector("input[type='text']");
        // 定义变量 记录防抖函数
        var fn = fangdou(function () {
            var v1 = inp.value;
            getData(v1);
        }, 1000)
        // 事件绑定
        inp.oninput = fn;

        // 请求数据的函数
        function getData(val) {
            console.log("输入的值:" + val);
        }



    </script>
</body>

</html>